package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.entity.system.Category;
import com.atguigu.spzx.model.entity.system.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.IndexVo;
import com.atguigu.spzx.product.service.CategoryService;
import com.atguigu.spzx.product.service.ProductSkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("/api/product/index")
@Tag(name = "首页接口管理")
@SuppressWarnings({"uncheck","rawtypes"})
public class IndexController {

    @Autowired
    private ProductSkuService productSkuService;

    @Autowired
    private CategoryService categoryService;
    @GetMapping
    @Operation(summary = "获取首页数据")
    //接口文档展示了categoryList和ProductSkuList集合
    public Result<IndexVo> findData (){
        //获取category一级分类
        List<Category> categoryList = categoryService.categoryList();
        //获取productSku对象
        List<ProductSku> productSkuList = productSkuService.productSkuList();
        //创建indexVo对象
        IndexVo indexVo = new IndexVo();
        //将categoryList封装进去
        indexVo.setCategoryList(categoryList);
        //将productSkuList封装进去
        indexVo.setProductSkuList(productSkuList);
        //将indexVo返回给前端
        return Result.OK(indexVo);
    }
}
